﻿using Super_Management_Mayhem.Content.Animations.Manager;
using System;
using Super_Management_Mayhem.Screens.Playing.AttackModel;
using Transformable_Engine_v2.Engine.Animation.FrameAnimation;
using Transformable_Engine_v2.Engine.GameObjects.Primitives;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Time;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Players.Manager
{
    public partial class Manager
    {
        private Timer _attackTimer;

        private BaseAttack _downAttack, _leftAttack, _rightAttack, _upAttack;

        public void InitializeAttackObjects()
        {
            _attackTimer = new Timer(1, false, AttackEnd);
            AddTimers(_attackTimer);

            _leftAttack = new UnidirectionalAttack(BaseAttack.TargetTeam.EnemyTo, _statistics.GetTeam(), _statistics, 4, 500, new TE_Rectangle(-24, -22, 20, 24), new TE_Vector2(-1, 0), 10);
            _rightAttack = new UnidirectionalAttack(BaseAttack.TargetTeam.EnemyTo, _statistics.GetTeam(), _statistics, 4, 500, new TE_Rectangle(4, -22, 20, 24), new TE_Vector2(1, 0), 10);
            _upAttack = new UnidirectionalAttack(BaseAttack.TargetTeam.EnemyTo, _statistics.GetTeam(), _statistics, 4, 500, new TE_Rectangle(-20, -31, 36, 22), new TE_Vector2(0, -1), 10);
            _downAttack = new UnidirectionalAttack(BaseAttack.TargetTeam.EnemyTo, _statistics.GetTeam(), _statistics, 4, 500, new TE_Rectangle(-12, -8, 28, 28), new TE_Vector2(0, 1), 10);
        }

        protected virtual void AttackEnd()
        {
            ChangeState(PlayerState.Idle);
        }

        private void HandleKeyPressAttackState(Input input) {}

        private void HandleKeyReleaseAttackState(Input input) {}

        private void InitializeAttackState()
        {
            SetAttackModel(_latestDirection);

            _attackTimer.Reset(GetAttackTime(_latestDirection));
        }

        protected virtual void UpdateAttackState(TimeSpan gameTime)
        {
            TE_Rectangle hitRectangle = null;
            TE_Vector2 hitDirection = null;
            switch (_latestDirection)
            {
                case Direction.Up:
                    _upAttack.Attack(_player.AbsolutePosition);
                    break;
                case Direction.Down:
                    _downAttack.Attack(_player.AbsolutePosition);
                    break;
                case Direction.Left:
                    _leftAttack.Attack(_player.AbsolutePosition);
                    break;
                case Direction.Right:
                    _rightAttack.Attack(_player.AbsolutePosition);
                    break;
            }
        }
    }
}
